import React, { useEffect } from 'react'
import { Form, Input } from "antd";
import { useDispatch, useSelector } from "umi"

export default function index({ reload }) {
    const [form] = Form.useForm();
    const { isClearForm } = useSelector(state => state.common)
    const dispatch = useDispatch();
    // 没次isClearForm进行判断内容，看是否进行刷新
    useEffect(() => {
        if (isClearForm) {
            form.resetFields();
            reload({});
            dispatch({
                type: "common/setIsClearForm",
                payload: false
            })
        }
    }, [isClearForm]);
    // 提交新的值
    const onSubmitNewValue = async () => {
        let res = await form.getFieldsValue();
        const key = Object.keys(res);
        for (const item of key) {
            if (!res[item]) {
                delete res[item];
            }
        }
        reload(res)
    }
    return (
        <Form layout='vertical' form={form}>
            <Form.Item label="职级名称" name="levelName">
                <Input placeholder='请输入搜索的职级名称' onPressEnter={onSubmitNewValue} />
            </Form.Item>
            <Form.Item label="职级描述" name="levelDescription">
                <Input placeholder='请输入搜索的职级描述' onPressEnter={onSubmitNewValue} />
            </Form.Item>
        </Form>)
}
